package operation.duoxianliu.demo01;

public class shuibei implements Runnable {
    private static int stqw = 100;
    private static int a = 0;
    private static int b = 0;

    @Override
    public void run() {
        while (true) {
            if ("实体店".equals(Thread.currentThread().getName())) {
                boolean b = syMthod();
                if (b) {
                    break;
                }
            }
            if ("官网".equals(Thread.currentThread().getName())) {
                synchronized (shuibei.class) {
                    if (stqw == 0) {
                        System.out.println("官网总共卖出"+a);
                        break;
                    } else {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        stqw--;
                        a++;
                        System.out.println(Thread.currentThread().getName() + "新款水杯还有" + stqw + "份");
                    }
                }
            }

        }


    }
        private static synchronized boolean syMthod () {
            if (stqw == 0) {
                System.out.println("实体店总共卖出"+b);
                return true;
            } else {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            stqw--;
            b++;
            System.out.println(Thread.currentThread().getName() + "新款水杯还有" + stqw + "份");
            return false;
        }
    }


